class GameSceneCenter extends BaseSprite {

    private ROUND_TIME: number = 16;

    bg: eui.Image;
    img_arrow: eui.Image;
    private lab_count: eui.Label;
    private lab_round: eui.Label;
    private lab_roundType: eui.Label;
    private lab_time: eui.BitmapLabel;

    private roundTime: number = 0;
    private isShake: boolean;

    constructor() {
        super();

        this.skinName = "GameSceneCenterSkin";
    }

    childrenCreated() {
        super.childrenCreated();

        this.x = GSConfig.width - this.width >> 1;
        this.y = GSConfig.height - this.height >> 1;

        this.showArrow = false;

        egret.Tween.get(this.img_arrow, {loop: true}).to({alpha: 0}, 300).to({alpha: 1}, 300);

        gameManager.timerManager.addEventListener(TimerManager.TIMER, this.timerHandler, this);
    }

    private timerHandler() {
        if (this.roundTime > 0) {
            this.roundTime--;
            this.lab_time.text = '' + (this.roundTime < 10 ? '0' + this.roundTime : this.roundTime);
            if (this.roundTime == 0 && this.isShake) {
                if (navigator.vibrate) {
                    navigator.vibrate(2000);
                }

                GameSound.play('sound_cooldown_over');
            }
        }
    }

    //更新牌堆
    updateCount() {
        this.lab_count.text = "" + game.roomPaidui;
    }

    //更新对局
    updateRound() {
        switch (game.roomRoundType) {
            case RoundType.duiju:
                this.lab_round.text = game.roomRoundCur + "/" + game.roomRound;
                this.lab_roundType.text = "局";
                break;
            case RoundType.quan:
                this.lab_round.text = Math.ceil(game.roomRoundCur / 4) + "/" + Math.ceil(game.roomRound / 4);
                this.lab_roundType.text = "圈";
                break;
        }
    }

    //设置箭头方向
    setArrowDir(dir: number) {
        this.showArrow = dir != 0;

        switch (dir) {
            case 1:
                this.img_arrow.horizontalCenter = 0;
                this.img_arrow.verticalCenter = 33;
                this.img_arrow.rotation = 90;
                break;
            case 2:
                this.img_arrow.horizontalCenter = 33;
                this.img_arrow.verticalCenter = 0;
                this.img_arrow.rotation = 0;
                break;
            case 3:
                this.img_arrow.horizontalCenter = 0;
                this.img_arrow.verticalCenter = -33;
                this.img_arrow.rotation = -90;
                break;
            case 4:
                this.img_arrow.horizontalCenter = -33;
                this.img_arrow.verticalCenter = 0;
                this.img_arrow.rotation = 180;
                break;
        }
    }

    reset() {
        this.roundTime = 0;
    }

    play(isShake?: boolean) {
        this.isShake = isShake;
        this.roundTime = this.ROUND_TIME;
    }

    set showArrow(bool: boolean) {
        this.img_arrow.visible = bool;
    }
}